
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>chapter4 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="chapter5.html" />
    
    
    <link rel="prev" href="chapter3.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="chapter1.html">
            
                <a href="chapter1.html">
            
                    
                    chapter1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="chapter2.html">
            
                <a href="chapter2.html">
            
                    
                    chapter2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="chapter3.html">
            
                <a href="chapter3.html">
            
                    
                    chapter3
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5" data-path="chapter4.html">
            
                <a href="chapter4.html">
            
                    
                    chapter4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="chapter5.html">
            
                <a href="chapter5.html">
            
                    
                    chapter5
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >chapter4</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="request">Request</h1>
<p>&#xFF0F;src/net/request.go</p>
<p>package http</p>
<p>&#x6807;&#x793A;&#x670D;&#x52A1;&#x7AEF;&#x6536;&#x5230;&#x7684;&#x6216;&#x8005;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x51FA;&#x7684;http&#x8BF7;&#x6C42;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x548C;&#x670D;&#x52A1;&#x7AEF;&#x7528;&#x6CD5;&#x57FA;&#x672C;&#x4E00;&#x6837;</p>
<p>type Request struct {</p>
<p>Method string //&#x533A;&#x5206;&#x8BF7;&#x6C42;&#x7C7B;&#x578B;(GET, POST, PUT, etc.)</p>
<p>URL *url.URL//&#x533A;&#x5206;URL&#x662F;&#x88AB;&#x670D;&#x52A1;&#x7AEF;&#x8BF7;&#x6C42;&#x7684;&#x8FD8;&#x662F;&#x5BA2;&#x6237;&#x7AEF;&#x53D1;&#x51FA;&#x7684;&#x8BF7;&#x6C42;</p>
<p>&#x5BF9;&#x4E8E;&#x5BA2;&#x6237;&#x7AEF;&#x8BF7;&#x6C42;&#xFF0C;&#x591A;&#x6570;&#x60C5;&#x51B5;&#x4E0B;&#x662F;&#x7A7A;&#x7684;</p>
<p>&#x5BF9;&#x4E8E;&#x670D;&#x52A1;&#x7AEF;&#x88AB;&#x8BF7;&#x6C42;&#x7684;URL&#x4ECE; RequestURI&#x7684;Request-Line &#x63D0;&#x53D6;</p>
<p>Proto      string // &quot;HTTP/1.0&quot;  //http &#x7248;&#x672C; HTTP/1.1 or HTTP/2</p>
<pre><code>ProtoMajor int    // 1

ProtoMinor int    // 0
</code></pre><p>Header Header //&#x8BF7;&#x6C42;&#x5934;&#xFF0C;&#x5982;&#x679C;&#x670D;&#x52A1;&#x5668;&#x6536;&#x5230;&#x8BF7;&#x6C42;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>   //    Host: example.com

//    accept-encoding: gzip, deflate

//    Accept-Language: en-us

//    fOO: Bar

//    foo: two

//
</code></pre><p>&#x5B58;&#x50A8;&#x683C;&#x5F0F;&#x5982;&#x4E0B;</p>
<pre><code>//

//    Header = map\[string\]\[\]string{

//        &quot;Accept-Encoding&quot;: {&quot;gzip, deflate&quot;},

//        &quot;Accept-Language&quot;: {&quot;en-us&quot;},

//        &quot;Foo&quot;: {&quot;Bar&quot;, &quot;two&quot;},

//    }
</code></pre><p>&#x5BF9;&#x4E8E;&#x5BA2;&#x6237;&#x7AEF;&#x8BF7;&#x6C42;&#x5934;&#x5B58;&#x5728;Request.Host&#xFF0C;&#x800C;&#x4E0D;&#x662F;Header map</p>
<p>http&#x534F;&#x8BAE;&#x5B9A;&#x4E49;&#x5934;&#x90E8;&#x4E0D;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#xFF0C;&#x8BF7;&#x6C42;&#x89E3;&#x6790;&#x5668;&#xFF0C;&#x628A;&#x5B83;&#x89E3;&#x6790;&#x6210;&#x9A7C;&#x5CF0;&#x683C;&#x5F0F;</p>
<p>&#x5BF9;&#x4E8E;&#x5BA2;&#x6237;&#x7AEF;&#x8BF7;&#x6C42;&#xFF0C;&#x8BF7;&#x6C42;&#x5934;&#x90E8;&#xFF0C;&#x6BD4;&#x5982;Content-Length&#x548C;Connection&#x4F1A;&#x88AB;&#x81EA;&#x52A8;&#x586B;&#x5199;&#xFF0C;Header&#x91CC;&#x9762;&#x7684;&#x5185;&#x5BB9;&#x4F1A;&#x88AB;&#x5FFD;&#x7565;</p>
<p>Body io.ReadCloser//&#x8BF7;&#x9700;&#x6C42;&#x5185;&#x5BB9;&#xFF0C;&#x5F53;&#x8FD4;&#x56DE;EOF&#x7B26;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x5173;&#x95ED;&#x8BF7;&#x6C42;&#x4F53;&#xFF0C;&#x4F46;&#x662F;&#x6CA1;&#x5FC5;&#x8981;&#x5173;&#x95ED;&#x8FDE;&#x63A5;</p>
<p>ContentLength int64 // &#x5185;&#x5BB9;&#x957F;&#x5EA6;&#xFF0C;&#xFF0D;1&#x6807;&#x793A;&#x672A;&#x77E5;</p>
<p>TransferEncoding []string //&#x4ECE;&#x6700;&#x5916;&#x5230;&#x6700;&#x5185;&#x7F16;&#x7801;&#x65B9;&#x5F0F;</p>
<p>Close bool //&#x670D;&#x52A1;&#x7AEF;&#x4F1A;&#x81EA;&#x52A8;&#x5904;&#x7406;&#xFF0C;&#x4E0D;&#x5173;&#x6CE8;&#x8FD9;&#x4E2A;&#x5B57;&#x6BB5;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x4F1A;&#x770B; Transport.DisableKeepAlives &#x662F;&#x5426;&#x88AB;&#x8BBE;&#x7F6E;</p>
<p>Host string //&quot;host:port&quot;</p>
<p>Form url.Values  // &#x5305;&#x542B;URL&#x91CC;&#x9762;&#x7684;&#x53C2;&#x6570;&#x548C;POST&#x6216;&#x8005;PATH  PUT &#x53C2;&#x6570;&#xFF0C;&#x53EA;&#x6709;ParseForm &#x65B9;&#x6CD5;&#x88AB;&#x8C03;&#x7528;&#x540E;&#x624D;&#x6709;&#x7528;</p>
<p>PostForm url.Values //POST&#x6216;&#x8005;PATH  PUT &#x53C2;&#x6570;&#xFF0C;&#x53EA;&#x6709;ParseForm &#x65B9;&#x6CD5;&#x88AB;&#x8C03;&#x7528;&#x540E;&#x624D;&#x6709;&#x7528;</p>
<p>MultipartForm *multipart.Form //&#x89E3;&#x6790;multipart form &#x5305;&#x62EC;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;</p>
<p>Trailer Header//&#x8BF7;&#x6C42;&#x4F53;&#x540E;&#x52A0;&#x7684;&#x989D;&#x5916;headers&#xFF0C;</p>
<p>RemoteAddr string //&#x8BB0;&#x5F55;&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x7684;ip&#x548C;&#x7AEF;&#x53E3;&#xFF0C;&#x4E00;&#x822C;&#x4F9B;&#x65E5;&#x5FD7;&#x4F7F;&#x7528;</p>
<p>RequestURI string //&#x672A;&#x88AB;&#x4FEE;&#x6539;&#x7684; Request-URI</p>
<p>TLS *tls.ConnectionState//&#x8BB0;&#x5F55;&#x63A5;&#x53D7;&#x5230;&#x8BF7;&#x6C42;&#x7684;TLS&#xFF0C;</p>
<p>Cancel &lt;-chan struct{}//&#x53EA;&#x6709;&#x5BA2;&#x6237;&#x7AEF;&#x53EF;&#x7528;&#xFF0C;&#x8868;&#x793A;&#x8FDE;&#x63A5;&#x662F;&#x56E0;&#x4E3A;&#x53D6;&#x6D88;&#x5173;&#x95ED;&#x7684;</p>
<p>&#xFF5D;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="chapter3.html" class="navigation navigation-prev " aria-label="Previous page: chapter3">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="chapter5.html" class="navigation navigation-next " aria-label="Next page: chapter5">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"chapter4","level":"1.5","depth":1,"next":{"title":"chapter5","level":"1.6","depth":1,"path":"chapter5.md","ref":"chapter5.md","articles":[]},"previous":{"title":"chapter3","level":"1.4","depth":1,"path":"chapter3.md","ref":"chapter3.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter4.md","mtime":"2017-04-24T12:36:05.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-24T12:46:36.957Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

